package com.mjh.zhujianju.controller.supervise;

import com.livew.framework.base.model.SysUser;
import com.livew.framework.base.service.SysUserService;
import com.livew.framework.exception.XTBusinessException;
import com.mjh.zhujianju.model.supervise.SupervisionEstimateEO;
import com.mjh.zhujianju.model.supervise.SupervisionScheduleEO;
import com.mjh.zhujianju.service.supervise.SupervisionEstimateService;
import com.mjh.zhujianju.service.supervise.SupervisionScheduleService;
import com.mjh.zhujianju.util.ApiConstant;
import com.mjh.zhujianju.util.JsonResult;
import com.mjh.zhujianju.vo.supervision.SupervisionEstimateVO;
import com.mjh.zhujianju.vo.supervision.SupervisionScheduleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author: Alex
 * @version: V1.0
 * @project: zhujianju
 * @package: com.mjh.zhujianju.controller.supervise
 * @description: description
 * @date: 2018/9/5
 * @time: 上午8:46
 */
@RestController
@RequestMapping("/estimate")
@Api("3.督办->评价")
public class SupervisionEstimateController {

	@Autowired
	private SupervisionEstimateService supervisionEstimateService;

	@Resource
	private SysUserService userService;

	@ApiOperation(value="督办->评价", notes="对督办进行评价")
	@RequestMapping(value = "/addSupervisionSchedule", method = RequestMethod.POST)
	@ApiImplicitParam(name = "督办评价类", value = "supervisionEstimateVO", required = true, dataType = "SupervisionEstimateVO")
	public ResponseEntity<JsonResult> addSupervisionSchedule (@RequestBody SupervisionEstimateVO supervisionEstimateVO){
		JsonResult result = new JsonResult();
		try {
			SupervisionEstimateEO supervisionEstimateEO = new SupervisionEstimateEO();
			BeanUtils.copyProperties(supervisionEstimateVO,supervisionEstimateEO);
			supervisionEstimateService.save(supervisionEstimateEO);
			result.setResult("评价成功");
			result.setStatus(ApiConstant.MSG_SUCCESS);
		}catch (XTBusinessException e){
			result.setResult(e.getClass().getName() + ":" + e.getMessage());
			result.setStatus(ApiConstant.MSG_ERROR);
			e.printStackTrace();
		}
		return ResponseEntity.ok(result);
	}

	@ApiOperation(value="信访->查看信件评价", notes="根据信件主键查询信件评价详情")
	@RequestMapping(value = "/letterEvaluateDetail/{id}/{openid}", method = RequestMethod.GET)
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "Long", paramType = "path"),
			@ApiImplicitParam(name = "openid", value = "微信用户id", required = true, dataType = "String", paramType = "path")

	})
	public ResponseEntity<JsonResult> letterEvaluateDetail (@PathVariable(value = "id")Long id, @PathVariable(value = "openid")String openid){
		JsonResult result = new JsonResult();
		SysUser user = userService.getUserByOpenid(openid);
		if (null == user){
			result.setResult("该用户没有找到");
			result.setStatus(ApiConstant.MSG_NO_USER);
			return ResponseEntity.ok(result);
		}
		SupervisionEstimateVO supervisionEstimateVO = supervisionEstimateService.queryLetterEvaluateDetail(id,user.getId());
		result.setResult(supervisionEstimateVO);
		return ResponseEntity.ok(result);
	}
}
